<?php


class MenuAction extends SecurityAction{
	function _initialize(){
        $this->assign("menuFirst",session('menuFirst')); 
        $this->assign("menuSecond",session('menuSecond')); 
    }
		
	function mlist(){
		
		if ($_GET['opt'] == 'add'){  //新增跳转

			$ob = M("yq_menu");
	        $menulist = $ob->where(array("pid"=>"0","display"=>"1"))->select();

	        $this->assign("menulist", $menulist);
			$this->display("Menu/detail");
			return;
		}


	    if ($_GET["opt"] == 'edit'){   //编辑
	        $ob = M("yq_menu");
	        $info = $ob->where(array("tid"=>$_GET["tid"]))->find();

	        //上级菜单
	        $menulist = $ob->where(array("pid"=>"0","display"=>"1"))->select();

	        $this->assign("menulist", $menulist);

	        $this->assign("modify", '1');
	        $this->assign("info", $info);
	        $this->display('Menu/detail');
	        return;
	    }

		$ob = M("yq_menu");
		
		if($_GET['name']){
		    $sql[] = array('name'=>array('like',"%{$_GET['name']}%"));
		}
		
		$cpp = 10; //分页数
        import('ORG.Util.Page');// 导入分页类
        $count      = $ob->where($sql)->count();// 查询满足要求的总记录数
        $Page       = new Page($count,$cpp);// 实例化分页类 传入总记录数和每页显示的记录数
        $show       = $Page->show();// 分页显示输出
        
		$list = $ob->where($sql)->limit($Page->firstRow.','.$Page->listRows)->select();

		$this->assign("list", $list);
		$this->assign('show',$show);// 赋值分页输出
		$this->display("Menu/mlist");
	}
	

	function detail(){
	    if($_POST){
	        //添加
	        $_POST['adminid'] = session('info.tid');
	        $_POST['add_time'] = time();//date('Y-m-d H:i:s', time());
	        $ob = M("yq_menu");
	    
	        if($_POST['tid'] != ''){
	            $ob->where(array('tid'=>$_POST['tid']))->save($_POST);
	        }else{
	            $ob->add($_POST);
	        }
	        	
	        $this->redirect('/Menu/mlist/');
	        return;
	    }
	}

}

?>